package se.id.vrapp;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.GraphView.GraphViewData;
import com.jjoe64.graphview.GraphViewSeries;
import com.jjoe64.graphview.GraphViewSeries.GraphViewSeriesStyle;
import com.jjoe64.graphview.LineGraphView;

public class StatusFragment extends Fragment {
	int mNum;
	boolean running;
	int progress = 0;
	TextView planned_speed;
	
	public static int plannedSpeed = 30;

	/**
	 * Create a new instance of CountingFragment, providing "num" as an
	 * argument.
	 */
	static StatusFragment newInstance(int num) {
		StatusFragment f = new StatusFragment();

		// Supply num input as an argument.
		Bundle args = new Bundle();
		args.putInt("num", num);
		f.setArguments(args);

		return f;
	}

	/**
	 * When creating, retrieve this instance's number from its arguments.
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mNum = getArguments() != null ? getArguments().getInt("num") : 1;
	}

	/**
	 * The Fragment's UI is just a simple text view showing its instance number.
	 */
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.status_view, container, false);

		final ProgressWheel pw = (ProgressWheel) v
				.findViewById(R.id.progressWheel);

		pw.spin();

		// Graph
		// graph with dynamically genereated horizontal and vertical labels
		// init example series data

		GraphViewData[] data = new GraphViewData[] {

		new GraphViewData(0, 1.0d),new GraphViewData(1, 1.5d), new GraphViewData(2, 1.2d),
				new GraphViewData(3, 1.4d), new GraphViewData(4, 1.5d),
				new GraphViewData(5, 1.7d), new GraphViewData(6, 1.5d),
				new GraphViewData(7, 2.0d), new GraphViewData(8, 2.3d),
				new GraphViewData(9, 1.0d) };
		
		GraphViewSeries exampleSeries = new GraphViewSeries("",
				new GraphViewSeriesStyle(Color.rgb(51, 155, 185), 3), data);

		GraphView graphView = new LineGraphView(getActivity(), "");
		((LineGraphView) graphView).setDrawBackground(true);
		((LineGraphView) graphView).setBackgroundColor(Color.rgb(51, 155, 185));
		graphView.getGraphViewStyle().setVerticalLabelsColor(Color.rgb(41, 44, 48));  
		graphView.getGraphViewStyle().setHorizontalLabelsColor(Color.rgb(41, 44, 48));  

		

		graphView.addSeries(exampleSeries); // data
		RelativeLayout layout = (RelativeLayout) v.findViewById(R.id.graph);
		layout.addView(graphView);
		
		planned_speed = (TextView) v.findViewById(R.id.textkmh2);
		
		return v;
	}
	
	@Override
	public void onResume() {
		super.onResume();
		planned_speed.setText(""+plannedSpeed);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
	}

}
